package com.qubuyer.core.app

import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import com.qubuyer.core.framework.BaseViewModel

/**
 * Author: linwg
 * Time: 2020/11/2 0002
 * Description:
 */
abstract class MVVMActivity<V : ViewDataBinding, VM : BaseViewModel> : DataBindingActivity<V>() {
    protected abstract val viewModel: VM

    inline fun <reified VM : BaseViewModel> injectVMByActivity(clazz: Class<VM> = VM::class.java): Lazy<VM> {
        return lazy {
            val vm = ViewModelProvider(this).get(clazz)
            vm.lifecycleOwner = this
            vm
        }
    }
}